package com.wondersgroup.fjzlpt.org.dao.impl.xyxx;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.repository.sql.bean.SQLBean;
import com.quick.framework.boot.repository.sql.bean.page.PageQuerySQLBean;
import com.quick.framework.boot.repository.sql.bean.table.TableBean;
import com.quick.framework.boot.repository.sql.jdbcTemplate.impl.BaseJTDAOImpl;
import com.quick.framework.boot.repository.sql.jdbcTemplate.rs.ResultHandlerConstant;
import com.wondersgroup.fjzlpt.org.dao.inter.xyxx.XyxxDAO;
@Repository("xyxxDao")
public class XyxxDAOImpl  extends BaseJTDAOImpl implements XyxxDAO {
	@Override
	@Autowired
	@Qualifier("TB_XXWH_XYXX")
	public void setTb(TableBean tb) {
		super.setTb(tb);
	}

	@Override
	public JSONObject queryPage(Map<String, String> map) {
		StringBuilder sbud = new StringBuilder("select a.*,b.YLJGDM from TB_XXWH_XYXX a, TB_ZD_YLJGXX b \n");
		sbud.append(" where a.YLJGID = b.YLJGDM  \n");
		List list = new ArrayList();
		String value = map.get("XYMBID");
		if(!StringUtils.isEmpty(value))
		{
			sbud.append("and a.XYMBID = ? ");
			list.add(value);
		}
		value = map.get("XYMBMC");
		if(!StringUtils.isEmpty(value))
		{
			sbud.append("and c.XYMBMC like ? ");
			list.add("%"+value+"%");
		}
		PageQuerySQLBean sb = checkAndCreatePageQuerySQLBean(map, sbud.toString(), "order by a.YLJGID, a.XYMBID ", list.toArray());
		return super.queryPage(sb, ResultHandlerConstant.JSONARRAY);
	}

	@Override
	public JSONObject queryOne(Map<String, String> map) {
		StringBuilder sbud = new StringBuilder("select a.*,b.YLJGDM from TB_XXWH_XYXX a, TB_ZD_YLJGXX b \n");
		sbud.append(" where a.YLJGID = b.YLJGDM  \n");
		List list = new ArrayList();
		String value = map.get("XYMBID");
		if(!StringUtils.isEmpty(value))
		{
			sbud.append("and a.XYMBID = ? ");
			list.add(value);
		}
		value = map.get("XYMBMC");
		if(!StringUtils.isEmpty(value))
		{
			sbud.append("and c.XYMBMC like ? ");
			list.add("%"+value+"%");
		}
		SQLBean sqlBean = new SQLBean(sbud.toString(),list.toArray());
		JSONObject jsonObject = super.queryOne(sqlBean);
		return jsonObject;
	}

}
